package com.swipemaster.record;

import java.io.Serializable;

import com.swipemaster.R;
import com.swipemaster.common.Global;

/** To distinguish records. */
public class RecordId implements Serializable
{
	private static final long serialVersionUID = 1L;

	/** Record types. */
	public final static int LEVEL = -1;
	public final static int CHALLENGE = -2;
	public final static int CUSTOM_GAME = -4;
	public final static int GAMES_PLAYED = -7;
	public final static int STARS = -8;
	public final static int CUSTOM_GAMES_PLAYED = -9;
	public final static int CHALLENGE_GAMES_PLAYED = -11;
	public final static int LEVEL_GAMES_PLAYED = -12;

	/** Internal record ID. Non-negative ID are for levels. */
	private int id;

	public RecordId(int id)
	{
		this.id = id;
	}

	public void advanceLevelIndex()
	{
		if (id < 0)
		{
			throw new IllegalStateException("This record does not contain level index, it's id = " + id);
		}
		id++;
	}

	public int getId()
	{
		return id;
	}

	/** @return If there is level index information, return it. */
	public int getLevelIndex()
	{
		if (id < 0)
		{
			throw new IllegalStateException("This record does not contain level index, it's id = " + id);
		}
		return id;
	}

	/** @return One of 8 record types. */
	public int getType()
	{
		if (id < 0)
		{
			return id;
		}
		return LEVEL;
	}

	@Override
	public String toString()
	{
		switch (getType())
		{
		case LEVEL:
			return Global.app.getString(R.string.level) + " " + (id + 1) + " ("
					+ Global.app.consts.getLevelTypeName(RecordsManager.getInfo(getLevelIndex()).isPuzzle) + ")";
		case CHALLENGE:
			return Global.app.getString(R.string.challenge_game);
		case CUSTOM_GAME:
			return Global.app.getString(R.string.custom_game);
		case GAMES_PLAYED:
			return Global.app.getString(R.string.games_played);
		case STARS:
			return Global.app.getString(R.string.stars);
		}
		throw new IllegalStateException("This record is no description for record id " + id);
	}
}
